import 'package:app/pages/daily_work_report_module/my_daily_detail_module/my_daily_detail_controller.dart';
import 'package:app/utils/hexcolor.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:get/get.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../../common/app_theme.dart';
import '../../../common/colors.dart';
import '../../../components/nodata_page.dart';
import '../../../services/address.dart';
import '../../../utils/search_module.dart';
import 'my_project_detail_controller.dart';

class MyMissionDetailView extends GetView {
  MyMissionDetailController controller = Get.put(MyMissionDetailController());

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        backgroundColor: AppColor.themeColor,
        title: Text('项目详情'),
        leading: IconButton(
          onPressed: () {
            Get.back();
          },
          icon: Image.asset(
            'images/leftarr.png',
            color: Colors.white,
            width: 15,
            height: 15,
          ),
        ),
      ),
      body: GetBuilder<MyMissionDetailController>(builder: (_) {
        return controller.model == null
            ? const Center(
                child: CupertinoActivityIndicator(),
              )
            : Column(
                children: [
                  Expanded(
                    child: GestureDetector(
                      behavior: HitTestBehavior.translucent,
                      onTap: () {
                        /// 页面点击响应
                        SearchModule.closeKeyboard(context);
                      },
                      onPanDown: (_) {
                        /// 列表滑动响应
                        SearchModule.closeKeyboard(context);
                      },
                      child: CustomScrollView(
                        slivers: [
                          SliverToBoxAdapter(
                            child: Container(
                              // margin: EdgeInsets.all(5),
                              // height: 10,
                              margin: EdgeInsets.only(top: 5),
                              padding: EdgeInsets.only(left: 15),
                              color: Colors.white,
                              child: Row(
                                children: [
                                  CircleAvatar(
                                    radius: 24,
                                    child: Image.asset("images/log_icon.png"),
                                  ),
                                  Container(
                                    margin: const EdgeInsets.only(
                                      left: 5,
                                    ),
                                    child: Column(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        Container(
                                          margin: EdgeInsets.only(top: 10),
                                          color: Colors.white,
                                          width: Get.width - 80,
                                          child: Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.spaceBetween,
                                            children: [
                                              Text(
                                                '${controller.model?.data?.name}',
                                                style: appThemeData
                                                    .textTheme.bodyText1,
                                              ),
                                              Text(
                                                '${controller.model?.data?.dateStart}',
                                                style: appThemeData
                                                    .textTheme.bodyText1!
                                                    .copyWith(
                                                        color:
                                                            AppColor.themeColor,
                                                        fontSize: 10),
                                              )
                                            ],
                                          ),
                                        ),
                                        const SizedBox(
                                          height: 3,
                                        ),
                                        Text(
                                          '管理员 : ${controller.model?.data?.managerName}',
                                          style: appThemeData
                                              .textTheme.subtitle1
                                              ?.copyWith(fontSize: 11),
                                        ),
                                        const SizedBox(
                                          height: 3,
                                        ),
                                        Text(
                                          '参与者 : ${controller.model?.data?.managerName}',
                                          style: appThemeData
                                              .textTheme.subtitle1
                                              ?.copyWith(fontSize: 11),
                                        ),
                                        const SizedBox(
                                          height: 3,
                                        ),
                                      ],
                                    ),
                                  )
                                ],
                              ),
                            ),
                          ),
                          SliverToBoxAdapter(
                            child: Container(
                              color: Colors.white,
                              margin:
                                  EdgeInsets.only(left: 15, right: 15, top: 10),
                              child: Text(
                                '详情：${controller.model?.data?.description}',
                                style: appThemeData.textTheme.bodyText1,
                              ),
                            ),
                          ),
                          SliverToBoxAdapter(
                            child: Container(
                              margin: EdgeInsets.only(top: 5),
                              height: 10,
                              width: Get.width,
                              color: AppColor.bgColor,
                            ),
                          ),
                          SliverToBoxAdapter(
                            child: Container(
                              padding: EdgeInsets.fromLTRB(20, 10, 20, 14),
                              color: HexColor('#F8F8F8'),
                              width: Get.width - 80,
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [Text("基本信息")],
                              ),
                            ),
                          ),
                          SliverToBoxAdapter(
                            child: SizedBox(
                              height: 2,
                              child: DecoratedBox(
                                decoration: BoxDecoration(
                                  color: HexColor("#F8F8F8"),
                                ),
                              ),
                            ),
                          ),
                          SliverToBoxAdapter(
                            child: Container(
                              padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
                              color: HexColor('#FEFEFE'),
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Text("负责人"),
                                  Container(
                                      height: 40,
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.spaceAround,
                                        crossAxisAlignment:
                                            CrossAxisAlignment.center,
                                        children: [
                                          Text('${controller.model?.data?.managerName}'),
                                          Icon(
                                            Icons.arrow_forward_ios,
                                            size: 15,
                                          )
                                        ],
                                      )),
                                ],
                              ),
                            ),
                          ),
                          SliverToBoxAdapter(
                            child: SizedBox(
                              height: 2,
                              child: DecoratedBox(
                                decoration: BoxDecoration(
                                  color: HexColor("#F8F8F8"),
                                ),
                              ),
                            ),
                          ),
                          SliverToBoxAdapter(
                            child: Container(
                              padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
                              color: HexColor('#FEFEFE'),
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Text("起始日"),
                                  Container(
                                      height: 40,
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.spaceAround,
                                        crossAxisAlignment:
                                            CrossAxisAlignment.center,
                                        children: [
                                          Text('${controller.model?.data?.dateStart}'),
                                          Icon(
                                            Icons.arrow_forward_ios,
                                            size: 15,
                                          )
                                        ],
                                      )),
                                ],
                              ),
                            ),
                          ),
                          SliverToBoxAdapter(
                            child: SizedBox(
                              height: 20,
                              child: DecoratedBox(
                                decoration: BoxDecoration(
                                  color: HexColor("#F8F8F8"),
                                ),
                              ),
                            ),
                          ),
                          SliverToBoxAdapter(
                            child: Container(
                              padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
                              color: HexColor('#FEFEFE'),
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Text("参与人"),
                                  Container(
                                      height: 40,
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.spaceAround,
                                        crossAxisAlignment:
                                            CrossAxisAlignment.center,
                                        children: [
                                          Text('${controller.model?.data?.managerName}'),
                                          Icon(
                                            Icons.arrow_forward_ios,
                                            size: 15,
                                          )
                                        ],
                                      )),
                                ],
                              ),
                            ),
                          ),
                          SliverToBoxAdapter(
                            child: SizedBox(
                              height: 2,
                              child: DecoratedBox(
                                decoration: BoxDecoration(
                                  color: HexColor("#F8F8F8"),
                                ),
                              ),
                            ),
                          ),
                          SliverToBoxAdapter(
                            child: Container(
                              padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
                              color: HexColor('#FEFEFE'),
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Text("到期日"),
                                  Container(
                                      height: 40,
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.spaceAround,
                                        crossAxisAlignment:
                                            CrossAxisAlignment.center,
                                        children: [
                                          Text('${controller.model?.data?.dateEnd}'),
                                          Icon(
                                            Icons.arrow_forward_ios,
                                            size: 15,
                                          )
                                        ],
                                      )),
                                ],
                              ),
                            ),
                          ),
                          SliverToBoxAdapter(
                            child: SizedBox(
                              height: 2,
                              child: DecoratedBox(
                                decoration: BoxDecoration(
                                  color: HexColor("#F8F8F8"),
                                ),
                              ),
                            ),
                          ),
                          SliverToBoxAdapter(
                            child: Container(
                              padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
                              color: HexColor('#FEFEFE'),
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  Text("进度"),
                                  Container(
                                      height: 40,
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.spaceAround,
                                        crossAxisAlignment:
                                            CrossAxisAlignment.center,
                                        children: [
                                          SizedBox(
                                            width: 240,
                                            child: Slider(
                                              min: 0.0,
                                              max: 1.0,
                                              value: (controller
                                                      .model?.data?.progress)! *
                                                  1.0,
                                              onChanged: (double svalue) {},
                                            ),
                                          ),
                                          Container(
                                              width: 40,
                                              child: Text(
                                                  "${((controller.model?.data?.progress)! * 100).floor()}%")),
                                        ],
                                      )),
                                ],
                              ),
                            ),
                          ),
                          SliverToBoxAdapter(
                            child: SizedBox(
                              height: 2,
                              child: DecoratedBox(
                                decoration: BoxDecoration(
                                  color: HexColor("#F8F8F8"),
                                ),
                              ),
                            ),
                          ),
                          SliverToBoxAdapter(
                            child: Container(
                              margin: EdgeInsets.only(left: 15, top: 10),
                              child: Row(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Text(
                                    '附件:',
                                    style: appThemeData.textTheme.subtitle1,
                                  ),
                                  Container(
                                    // height: 200,
                                    width: Get.width - 60,
                                    child: ListView.builder(
                                      physics:
                                      const NeverScrollableScrollPhysics(),
                                      shrinkWrap: true,
                                      itemBuilder:
                                          (BuildContext context, int index) {
                                        return GestureDetector(
                                          onTap: () async {
                                            await launch(
                                              '${controller.fileModel?.data?[index].url}',
                                              forceSafariVC: false,
                                              forceWebView: false,
                                            );

                                            // Get.to(MyWebView('', _fileModel?.data?[index].url));
                                          },
                                          child: Container(
                                            padding: EdgeInsets.only(
                                                top: index != 0 ? 10 : 0),
                                            child: Row(
                                              mainAxisAlignment:
                                              MainAxisAlignment
                                                  .spaceBetween,
                                              children: [
                                                Row(
                                                  children: [
                                                    FlutterLogo(),
                                                    // Image.network('${Address.homeHost}${_fileModel?.data?[index].icon}'),
                                                    Container(
                                                      width: Get.width - 100,
                                                      child: Text(
                                                          '${controller.fileModel?.data?[index].name}'),
                                                    ),
                                                  ],
                                                ),
                                                GestureDetector(
                                                  onTap: () {
                                                    Get.bottomSheet(BottomSheet(
                                                      onClosing: () {},
                                                      builder: (BuildContext
                                                      context) {
                                                        return Container(
                                                          height: 50,
                                                          color: Colors.white,
                                                          child:
                                                          GestureDetector(
                                                            onTap: () async {
                                                              Get.back();
                                                              await launch(
                                                                '${controller.fileModel?.data?[index].url}',
                                                                forceSafariVC:
                                                                false,
                                                                forceWebView:
                                                                false,
                                                              );
                                                            },
                                                            child: Center(
                                                              child: Text('下载'),
                                                            ),
                                                          ),
                                                        );
                                                      },
                                                    ));
                                                  },
                                                  child: Image.asset(
                                                    'images/more_icon.png',
                                                    width: 15,
                                                    height: 15,
                                                  ),
                                                )
                                              ],
                                            ),
                                          ),
                                        );
                                      },
                                      itemCount:
                                      controller.fileModel?.data?.length ??
                                          0,
                                    ),
                                  )
                                  // Image.network('')
                                ],
                              ),
                            ),
                          ),
                          controller.commentModel?.data == null
                              ? const SliverToBoxAdapter(
                                  child: SizedBox(height: 1),
                                )
                              : SliverToBoxAdapter(
                                  child: Container(
                                      alignment: Alignment.centerLeft,
                                      width: Get.width,
                                      height: 35,
                                      color: Colors.white,
                                      padding: const EdgeInsets.only(left: 15),
                                      child: Column(
                                        // mainAxisAlignment: MainAxisAlignment.center,
                                        children: [
                                          const SizedBox(
                                            height: 10,
                                          ),
                                          Text(
                                            '评论(${controller.model?.data?.comments})',
                                            style: appThemeData
                                                .textTheme.subtitle1!
                                                .copyWith(
                                                    color: AppColor.themeColor),
                                          ),
                                          const SizedBox(
                                            height: 5,
                                          ),
                                          Container(
                                            margin: EdgeInsets.only(top: 3),
                                            color: AppColor.themeColor,
                                            width: 20,
                                            height: 10,
                                          )
                                        ],
                                      )),
                                ),
                          controller.commentModel?.data == null
                              ? const SliverToBoxAdapter(
                                  child: SizedBox(height: 1),
                                )
                              : SliverToBoxAdapter(
                                  child: Container(
                                    width: Get.width,
                                    height: 10,
                                    color: AppColor.bgColor,
                                  ),
                                ),
                          controller.commentModel?.data == null
                              ? SliverToBoxAdapter(
                                  child: Container(
                                    color: AppColor.bgColor,
                                    width: Get.width,
                                    height: 200,
                                    child: NoDataPage(
                                      text: '暂无评论',
                                    ),
                                  ),
                                )
                              : SliverList(
                                  delegate: _mySliverChildBuilderDelegate(),
                                ),
                        ],
                      ),
                    ),
                  ),
                  Container(
                    height: 50,
                    color: Colors.grey.shade200,
                    child: Center(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Container(
                            width: Get.width - 100,
                            height: 35,
                            decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius:
                                  BorderRadius.all(Radius.circular(20)),
                            ),
                            padding: EdgeInsets.only(left: 5),
                            alignment: Alignment.center,
                            child: TextField(
                              controller: controller.commentTextEditing,
                              decoration: InputDecoration(
                                  isCollapsed: true,
                                  border: InputBorder.none,
                                  hintText: '请输入评论内容'),
                            ),
                          ),
                          IconButton(
                              onPressed: () {
                                controller.tapClickSendComment();
                                // if (_commentTextEditing.text.isEmpty) {
                                //   BotToast.showText(text: '评论不能为空');
                                //   return;
                                // }
                                // requestDataWithMessageAdd(_model?.data?.id);
                                // requestDataWithComment();
                                // requestData(id: widget.id);
                                // _commentTextEditing.text = '';
                                // SearchModule.closeKeyboard(context);
                              },
                              icon: Icon(
                                Icons.send,
                                color: AppColor.smallTextColor,
                              )),
                        ],
                      ),
                    ),
                  )
                ],
              );
      }),
    );
  }

  _mySliverChildBuilderDelegate() {
    return SliverChildBuilderDelegate(
      (BuildContext context, int index) {
        return Column(
          children: [
            Container(
              color: Colors.white,
              padding: EdgeInsets.only(left: 15, right: 15, top: 5, bottom: 5),
              // height: 10,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    children: [
                      CircleAvatar(
                        radius: 15,
                        child: Image.network(
                            '${Address.homeHost}${controller.commentModel?.data?[index].headerImg}'),
                      ),
                      SizedBox(
                        width: 5,
                      ),
                      Text(
                        '${controller.commentModel?.data?[index].author}',
                        style: appThemeData.textTheme.subtitle1,
                      ),
                    ],
                  ),
                  Container(
                    margin: EdgeInsets.only(top: 5),
                    child: Text(
                      '${controller.commentModel?.data?[index].comment}',
                      style: appThemeData.textTheme.bodyText1!
                          .copyWith(fontSize: 13),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(top: 5),
                    child: Text(
                      '${controller.commentModel?.data?[index].dateBeauty}',
                      style: appThemeData.textTheme.subtitle1,
                    ),
                  ),
                ],
              ),
            ),
            Container(
              height: 10,
              color: AppColor.bgColor,
            )
          ],
        );
      },
      childCount: controller.commentModel?.data?.length,
    );
  }
}
